package com.leyou.item.mapper;

import com.leyou.pojo.Brand;
import com.leyou.pojo.Category;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface BrandMapper extends Mapper<Brand> {
	/**
	 * 新增商品分类和品牌中间表
	 *
	 * @param cid 商品分类ID
	 * @param bid 品牌ID
	 */
	@Insert("insert into tb_category_brand values (#{cid},#{bid})") int insertCategoryBrand(
			@Param("cid") Long cid, @Param("bid") Long bid);

	List<Category> queryByBrandId(Long bid);

	/**
	 * 删除品牌对应的分类
	 *
	 * @param bid
	 */
	@Delete("delete from tb_category_brand where brand_id = #{bid}")
	void deleteCategory(@Param("bid") Long bid);

	/**
	 * 删除品牌
	 *
	 * @param bid
	 */
	@Delete("delete from tb_brand where id = #{bid}")
	void deleteBrand(Long bid);

	/**
	 * 根据分类动态查询品牌
	 *
	 * @param cid
	 * @return
	 */
	@Select("select tb.id,tb.name,tb.image,tb.letter from tb_brand tb inner join "
			+ "tb_category_brand cb on tb.id=cb.brand_id where cb.category_id = #{cid} ")
	List<Brand> queryByCategoryId(Long cid);
}